﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quality_Calculator.Skills
{
    class SynthSkill : SkillBase
    {
        public double Efficiency { get; set; }
        public int Chance { get; set; }

        private int UsageCount { get; set; }
        private int SuccessCount { get; set; }
        private double TotalEfficiency { get; set; }

        public double AvgEfficiency
        {
            get
            {
                return TotalEfficiency / (double)SuccessCount;
            }
        }
        public double FailRate
        {
            get
            {
                return ((double)(UsageCount - SuccessCount) / (double)UsageCount) * 100f;
            }
        }

        public override void SpellEffect(Synthesis synth)
        {
            UsageCount++;
            GenericSynth(Efficiency, Chance, synth);
        }
        private void GenericSynth(double efficiency, int chance,Synthesis synth)
        {
            if (synth.HasBuff(eSpell.SteadyHands)) chance = chance + 20;
            if (synth.HasBuff(eSpell.SteadyHands2)) chance = chance + 30;
            if (synth.Randomize() <= chance)
            {
                double Progress = Formulas.Progress(synth.CraftmanShip);

                if (synth.HasBuff(eSpell.Ingenuity2))
                    Progress = Progress * 1.1481481481;
                else if (!synth.HasBuff(eSpell.Ingenuity))
                    Progress = Progress * 0.55;
                Progress *= efficiency;
                synth.ProgressCurrent += (int)Math.Round(Progress);
                //Stats
                SuccessCount++;
                TotalEfficiency += Progress;
            }
            synth.LooseDurability(this.DurabilityCost);
        }
    }
}
